﻿Imports System.Windows.Forms

Public Class dlgNewSubCategory

#Region "Property"

    ''' <summary>
    ''' Thuộc tính lưu đối tượng xử lý các thao tác nghiệp vụ
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 24/10/2010</remarks>
    Private m_oBusinessObject As BL.clsBLBase
    Public Property BusinessObject() As BL.clsBLBase
        Get
            Return m_oBusinessObject
        End Get
        Set(ByVal value As BL.clsBLBase)
            m_oBusinessObject = value
        End Set
    End Property

    ''' <summary>
    ''' Thuộc tính lưu tên chủng loại phụ
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 15/11/2010</remarks>
    Private m_SubCategoryName As String
    Public Property SubCategoryName() As String
        Get
            Return m_SubCategoryName
        End Get
        Set(ByVal value As String)
            m_SubCategoryName = value
        End Set
    End Property

    ''' <summary>
    ''' Thuộc tính lưu ID của chủng loại
    ''' </summary>
    ''' <remarks>Nguyễn Huy Thường added on 27/08/2011</remarks>
    Private m_CategoryID As Guid
    Public Property CategoryID() As Guid
        Get
            Return m_CategoryID
        End Get
        Set(ByVal value As Guid)
            m_CategoryID = value
        End Set
    End Property

#End Region

#Region "Event"

    ''' <summary>
    ''' Bấm thêm thì thực hiện việc thêm chủng loại
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Nguyễn Huy Thường added on 14/08/2011</remarks>
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Try
            If vldCheckInput.Validate.IsValid Then
                SubCategoryName = txtSubCategoryName.Text
                Dim drNewRow As BL.FMSDataSet.SubCategoryRow = BusinessObject.dsFMS.SubCategory.NewSubCategoryRow
                With drNewRow
                    .SubCategoryID = Guid.NewGuid
                    .CategoryID = CategoryID
                    .SubCategoryAlias = txtSubCategoryAlias.Text
                    .SubCategoryName = SubCategoryName
                    .SubCategoryAddedDate = Today
                    .SubCategoryStatus = True
                    .SubCategoryDescription = txtDescription.Text
                End With
                If BusinessObject.EditRecord(drNewRow) Then
                    BusinessObject.dsFMS.SubCategory.Rows.Add(drNewRow)
                    BusinessObject.dsFMS.SubCategory.AcceptChanges()
                    Me.DialogResult = System.Windows.Forms.DialogResult.OK
                    Me.Close()
                Else
                    SubCategoryName = String.Empty
                End If
            End If
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub

    ''' <summary>
    ''' Bấm cancel thì hủy việc thay đổi dữ liệu
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>Nguyễn Huy Thường added on 14/08/2011</remarks>
    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Try
            BusinessObject.dsFMS.SubCategory.RejectChanges()
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Close()
        Catch ex As Exception
            clscommon.ShowException(ex.Message)
        End Try
    End Sub
#End Region

End Class
